package com.tarena.lbs.basic.web.repoistory.impl;

import com.alibaba.nacos.common.utils.CollectionUtils;
import com.tarena.lbs.basic.web.mapper.AreaMapper;
import com.tarena.lbs.basic.web.repoistory.AreaRepository;
import com.tarena.lbs.pojo.basic.bo.AreaBO;
import com.tarena.lbs.pojo.basic.dos.AreaDO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
public class AreaRepositoryImpl implements AreaRepository {
    @Autowired
    private AreaMapper areaMapper;

    @Override
    public List<AreaBO> queryAreaList(long parentId) {
        List<AreaDO> areaDOList = areaMapper.selectAreasByParentId(parentId);
        List<AreaBO> bos=null;
        if (CollectionUtils.isNotEmpty(areaDOList)){
            bos=areaDOList.stream().map(areaDO->{
                AreaBO areaBO=new AreaBO();
                BeanUtils.copyProperties(areaDO,areaBO);
                return areaBO;
            }).collect(Collectors.toList());
        }
        return bos;
    }
}
